package com.ruoyi.cms.service.impl;

import java.util.List;
import java.util.ArrayList;
import com.ruoyi.common.core.domain.Ztree;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.cms.mapper.CmsChannelMapper;
import com.ruoyi.cms.domain.CmsChannel;
import com.ruoyi.cms.service.ICmsChannelService;
import com.ruoyi.common.core.text.Convert;

/**
 * 栏目信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-07-30
 */
@Service
public class CmsChannelServiceImpl implements ICmsChannelService 
{
    @Autowired
    private CmsChannelMapper cmsChannelMapper;

    /**
     * 查询栏目信息
     * 
     * @param channelId 栏目信息ID
     * @return 栏目信息
     */
    @Override
    public CmsChannel selectCmsChannelById(Long channelId)
    {
        return cmsChannelMapper.selectCmsChannelById(channelId);
    }

    /**
     * 查询栏目信息列表
     * 
     * @param cmsChannel 栏目信息
     * @return 栏目信息
     */
    @Override
    public List<CmsChannel> selectCmsChannelList(CmsChannel cmsChannel)
    {
        return cmsChannelMapper.selectCmsChannelList(cmsChannel);
    }

    /**
     * 新增栏目信息
     * 
     * @param cmsChannel 栏目信息
     * @return 结果
     */
    @Override
    public int insertCmsChannel(CmsChannel cmsChannel)
    {
        cmsChannel.setStatus("0");
        cmsChannel.setDelFlag("0");
        cmsChannel.setCreateTime(DateUtils.getNowDate());
        return cmsChannelMapper.insertCmsChannel(cmsChannel);
    }

    /**
     * 修改栏目信息
     * 
     * @param cmsChannel 栏目信息
     * @return 结果
     */
    @Override
    public int updateCmsChannel(CmsChannel cmsChannel)
    {
        cmsChannel.setDelFlag(null);
        cmsChannel.setUpdateTime(DateUtils.getNowDate());
        return cmsChannelMapper.updateCmsChannel(cmsChannel);
    }

    /**
     * 删除栏目信息对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteCmsChannelByIds(String ids)
    {
        return cmsChannelMapper.deleteCmsChannelByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除栏目信息信息
     * 
     * @param channelId 栏目信息ID
     * @return 结果
     */
    @Override
    public int deleteCmsChannelById(Long channelId)
    {
        return cmsChannelMapper.deleteCmsChannelById(channelId);
    }

    /**
     * 查询栏目信息树列表
     * 
     * @return 所有栏目信息信息
     */
    @Override
    public List<Ztree> selectCmsChannelTree()
    {
        List<CmsChannel> cmsChannelList = cmsChannelMapper.selectCmsChannelList(new CmsChannel());
        List<Ztree> ztrees = new ArrayList<Ztree>();
        for (CmsChannel cmsChannel : cmsChannelList)
        {
            Ztree ztree = new Ztree();
            ztree.setId(cmsChannel.getChannelId());
            ztree.setpId(cmsChannel.getParentId());
            ztree.setName(cmsChannel.getChannelName());
            ztree.setTitle(cmsChannel.getChannelName());
            ztrees.add(ztree);
        }
        return ztrees;
    }
}
